using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Routing;
using Thor.Domain;
using Thor.Domain.Configuration;

namespace Thor.WebRole.Controllers
{
    public class ConfigurationController : AuthenticatedController
    {
        public ActionResult Index()
        {
            //Check if settings have been configured and at least one administrator has been specified
            if (SettingsHelper.AreSettingsConfigured() && AdministratorAccountHelper.GetManager().Administrators != null &&
                AdministratorAccountHelper.GetManager().Administrators.Count > 0)
            {
                //Verify the user has been authenticated
                if (IsAuthenticated())
                    return View();
                else
                {
                    //If the user has not been authenticated, redirect to the account controller.
                    //The account controller manages whether or not the user has access to this page.
                    RouteValueDictionary d = new RouteValueDictionary();
                    d.Add("ReturnUrl", "/Configuration");

                    return RedirectToAction("Index", "Account", d);
                }
            }
            else
                return View();
        }

    }
}